package com.jinzhi.jzweb.controller.backstage;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.JazInterviewDO;
import com.jinzhi.jzweb.domain.JazMessageDO;
import com.jinzhi.jzweb.domain.JazUserAuntDO;
import com.jinzhi.jzweb.domain.param.UserInterViewQuery;
import com.jinzhi.jzweb.domain.vo.userAunt.UserAuntVO;
import com.jinzhi.jzweb.domain.vo.userAunt.UserVO;
import com.jinzhi.jzweb.service.JazInterviewService;
import com.jinzhi.jzweb.service.JazMessageService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 * @author ChangPanYuan
 * @Date 2024/5/14
 * @Description: 后台面试邀约
 * @Version 1.0
 */
@Controller
@RequestMapping("/userInterview")
@Api(value = "用户需求后台管理--面试邀约", tags = "用户需求后台管理--面试邀约")
public class JazInterviewController extends BaseController{

    @Autowired
    private JazInterviewService jazInterviewService;

    @Autowired
    private JazMessageService jazMessageService;



    @ApiOperation(value = "分页查面试邀约信息", notes = "分页查面试邀约信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "UserInterViewQuery", value = "UserInterViewQuery", required = true, dataType = "UserInterViewQuery"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping(value = "/getUserInterviewPage")
    @RequiresPermissions("jzweb:interviewInvitation:list")
    public Result<Page<JazInterviewDO>> getUserAuntPage(@RequestBody UserInterViewQuery userInterViewQuery){
        return Result.ok(jazInterviewService.getUserInterviewPage(userInterViewQuery));
    }

    @ApiOperation(value = "根据id查询详细信息", notes = "根据id查询详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping(value = "/getUserInterviewById")
    public Result<JazInterviewDO> getUserAuntById(@RequestParam("id") Long id){
        return Result.ok(jazInterviewService.getUserInterviewById(id));
    }

    @Log(value = "修改面试结果",sysModule = 3,operationType = 3)
    @ApiOperation(value = "修改面试结果", notes = "修改面试结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "id"),
            @ApiImplicitParam(name = "result", value = "result", required = true, dataType = "result"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping(value = "/updateUserInterview")
    public Result updateUserInterview(@RequestBody JazInterviewDO jazInterviewDO){
        return jazInterviewService.updateUserInterview(jazInterviewDO);
    }

    @Log(value = "删除面试邀约",sysModule = 3,operationType = 2)
    @ApiOperation(value = "删除面试邀约", notes = "删除面试邀约")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping(value = "/deletedById")
    @Transactional(rollbackFor = Exception.class)
    public Result<Object> deletedById(@RequestParam("id") Long id){
        JazInterviewDO jazInterviewDO = jazInterviewService.selectById(id);
        if (jazInterviewDO==null){
            return Result.fail();
        }
        // 删除消息  用户找阿姨，没有需求id
        if (jazInterviewDO.getDemandId()==null){
            jazMessageService.delete(new EntityWrapper<JazMessageDO>()
                    .eq("interview_id",jazInterviewDO.getId()));
        }else {
            jazMessageService.delete(new EntityWrapper<JazMessageDO>()
                    .eq("sender_id",jazInterviewDO.getInviterId())
                    .eq("demand_id", jazInterviewDO.getDemandId()));
        }
        boolean b = jazInterviewService.deleteById(id);
        return b?Result.ok():Result.fail();
    }

    @Log(value = "推送面试邀约",sysModule = 3,operationType = 3)
    @ApiOperation(value = "面试邀约-确认推送", notes = "面试邀约-确认推送")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "JazInterviewDO", value = "JazInterviewDO", required = true, dataType = "JazInterviewDO"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping(value = "/userInterviewPush")
    public Result getUserAuntPage(@RequestBody JazInterviewDO jazInterviewDO){
        return jazInterviewService.userInterviewPush(jazInterviewDO);
    }


    @ApiOperation(value = "查月嫂信息", notes = "查月嫂信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "", value = "", required = true, dataType = ""),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping(value = "/getUserInterviewAunt")
    public Result<List<UserVO>> getUserAunt(Long id,Long inviterId,String projectId,Long inviteeId){
        return Result.ok(jazInterviewService.getUserInterviewAunt(id,inviterId,projectId,inviteeId));
    }


}
